import NetWork from '/utils/modules/NetWork';
import {Config} from '/config';

App({
	onLaunch (){},
  onShow (){},
  onHide (){},

  /**
   * trigger 一个值
   */
  trigger (_event, _that){
    var _value = _event.currentTarget.dataset;
    var result = {};

    for(var i in _value){

      if(i.indexOf('jia_') == 0){
        var _key = i.replace('jia_', '');
        if(_value[i] == '^'){
          result[_key] = !_that.data[_key];
        }else{
          result[_key] = _value[i];
        }
      }
    }
    _that.setData(result);
  },

  /**
   * 返回网络请求类
   * @param {配置参数} options 
   * @param {类型} type 
   */
   http (options, type = 'request'){

    let net = new NetWork(Config.baseUrl, '/pages/personal/personal');
    return net._http(options, type);
  },

  /**
   * 设置标题
   * @param {页面标题} str 
   * @param {回调函数} fn 
   */
  setTitle (str, fn = () => {}) {
   	wx.setNavigationBarTitle({
   		title: str,
   		success: function () {
        fn();
      }
   	})
   },

   /* 隐藏分享功能 */
  hideShare() {
   	wx.hideShareMenu();
  },

   /* 分享功能 */
  showShare() {
   	wx.showShareMenu()
  },

   /* 拨打电话 */
  telPhone(tel, callback = () => {}) {
   	var that = this;
   	wx.makePhoneCall({
   		phoneNumber: tel
   	}, res => {
      callback()
    });
  },

  store : {
    user_type : wx.getStorageSync('userType') || '',  // default, live, store
    
    // custom组件获取数据
    custom : {
      StatusBar: 0,
      CustomBar: {},
      Custom: 0,
      System : {},
      IsCorrecting : false   // 数据是否已经校正
    },
    cartStore : {
      
    }
  },
  
});